package com.zy.xuanwo.zyc.portal.service.imp;

import android.content.Context;


import com.zy.xuanwo.zyc.portal.bean.Device;
import com.zy.xuanwo.zyc.portal.bean.DeviceControlPortal;
import com.zy.xuanwo.zyc.portal.bean.ErrorMessag;
import com.zy.xuanwo.zyc.portal.bean.LoginToken;
import com.zy.xuanwo.zyc.portal.bean.Product;
import com.zy.xuanwo.zyc.portal.bean.ScheduleCreat;
import com.zy.xuanwo.zyc.portal.bean.ScheduleCreatParameter;
import com.zy.xuanwo.zyc.portal.bean.WxApp;
import com.zy.xuanwo.zyc.portal.bean.WxAppParameter;
import com.zy.xuanwo.zyc.portal.callback.DeviceContrlPortalListener;
import com.zy.xuanwo.zyc.portal.callback.DeviceListener;
import com.zy.xuanwo.zyc.portal.callback.GetCommonResultListener;
import com.zy.xuanwo.zyc.portal.callback.LoginListener;
import com.zy.xuanwo.zyc.portal.callback.ProductListener;
import com.zy.xuanwo.zyc.portal.callback.ScheduleCreatListener;
import com.zy.xuanwo.zyc.portal.callback.WxAppListener;
import com.zy.xuanwo.zyc.portal.parser.imp.DeviceControlPortalParser;
import com.zy.xuanwo.zyc.portal.parser.imp.DeviceInParser;
import com.zy.xuanwo.zyc.portal.parser.imp.DevicesParser;
import com.zy.xuanwo.zyc.portal.parser.imp.LoginParser;
import com.zy.xuanwo.zyc.portal.parser.imp.ProductParser;
import com.zy.xuanwo.zyc.portal.parser.imp.ProductsDevicesImportParser;
import com.zy.xuanwo.zyc.portal.parser.imp.RegistParser;
import com.zy.xuanwo.zyc.portal.parser.imp.ScheduleCreateParser;
import com.zy.xuanwo.zyc.portal.parser.imp.SimpleParser;
import com.zy.xuanwo.zyc.portal.parser.imp.WxAppParser;
import com.zy.xuanwo.zyc.portal.service.IportalManager;
import com.zy.xuanwo.zyc.portal.service.command.RequestMand;
import com.zycver.http.callback.ResponseCallback;
import com.zycver.http.entity.RequestBean;
import com.zycver.http.iml.CustomRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public class PortalMagger extends IportalManager {
    private static PortalMagger mIPortalManager;
    private CustomRequest mCustomRequest;
    private static String PORTAL_ADDRESS;

    public synchronized static PortalMagger getInstance(Context context) {
        if (mIPortalManager == null) {
            mIPortalManager = new PortalMagger(context);
        }
        return mIPortalManager;
    }

    public PortalMagger(Context mContext) {
        if (null == mCustomRequest) {
            mCustomRequest = CustomRequest.getInstance(mContext);
        }
    }

    public boolean initAdress(String address) {
        if (address != null && address.trim().length() > 0) {
            PORTAL_ADDRESS = address;
            return true;
        } else {
            return false;
        }
    }


    @Override
    public void Cancle(String cancleHandler) {
        mCustomRequest.requestCancle(cancleHandler);

    }

    /**
     *
     * @param type      获取验证码的类型 1 email 2 手机短信 (必传)
     * @param username  邮箱或者手机号码（必传）
     * @param headerMap 请求头
     * @param mCommonResultListener
     */
    @Override
    public void VerificationCode(int type, String username, HashMap<String, String> headerMap,
                                 final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        if (type == 1) {
            mRequestBean.setStrCommand(RequestMand.USERS_EMAIL_VERIFICATION_CODE);
        } else {
            mRequestBean.setStrCommand(RequestMand.USERS_SMS_VERIFICATION_CODE);
        }
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param username(必传)
     * @param password(必传)
     * @param verification_code(必传)
     * @param headerMap
     * @param user_type(必传)             用户：user 开发者：developer
     * @param mCommonResultListener(必传)
     */
    @Override
    public void users(String username, String password, String verification_code, HashMap<String, String> headerMap, String user_type, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("password", password);
        prarm.put("verification_code", verification_code);
        prarm.put("user_type", user_type);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.USERS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                RegistParser registParser = new RegistParser();
                try {
                    ErrorMessag messag = registParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String token = registParser.parserJSON(mJSONObject.toString());
                        if (token != null) {
                            mCommonResultListener.onSuccess(token);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param username(必传)
     * @param password(必传)
     * @param headerMap
     * @param mLoginListener(必传)
     */
    @Override
    public void usersLogin(String username, String password, HashMap<String, String> headerMap, final
    LoginListener mLoginListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("password", password);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.USERS_LOGIN);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                LoginParser loginParser = new LoginParser();
                try {
                    ErrorMessag messag = loginParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        LoginToken mLoginToken = loginParser.parserJSON(mJSONObject.toString());
                        if (mLoginToken != null) {
                            mLoginListener.onSuccess(mLoginToken);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mLoginListener.RESPONSE_PARSION_JSON_ERROR);
                            mLoginListener.onFail(messag);
                        }
                    } else {
                        mLoginListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mLoginListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mLoginListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mLoginListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param username
     * @param password
     * @param headerMap
     * @param commonResultListener
     */
    @Override
    public void usersPasswordReset(String username, String password, HashMap<String, String> headerMap,
                                   final GetCommonResultListener commonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("password", password);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.USERS_PASSWORD_RESET);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            commonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(commonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            commonResultListener.onFail(messag);
                        }
                    } else {
                        commonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    commonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                commonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                commonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param username
     * @param password
     * @param hashMap
     * @param commonResultListener
     */
    @Override
    public void usersPassword(String username, String password,String new_password, HashMap<String, String> hashMap, final GetCommonResultListener commonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("password", password);
        prarm.put("new_passwrod",new_password);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (hashMap != null) {
            mRequestBean.setHeadersMap(hashMap);
        }
        mRequestBean.setStrCommand(RequestMand.USERS_PASSWORD);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            commonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(commonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            commonResultListener.onFail(messag);
                        }
                    } else {
                        commonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    commonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                commonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                commonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param product_id
     * @param MAC
     * @param secret_key
     * @param alias
     * @param encrypt_method
     * @param headerMap
     * @param mDeviceListener
     */
    @Override
    public void devices(String product_id, String MAC, String secret_key, String alias,
                        String encrypt_method, HashMap<String, String> headerMap, final DeviceListener mDeviceListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("product_id", product_id);
        prarm.put("MAC", MAC);
        prarm.put("secret_key", secret_key);
        prarm.put("alias", alias);
        prarm.put("encrypt_method", encrypt_method);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                DevicesParser devicesParser = new DevicesParser();
                try {
                    ErrorMessag messag = devicesParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        Device mDevice = devicesParser.parserJSON(mJSONObject.toString());
                        if (mDevice != null) {
                            mDeviceListener.onSuccess(mDevice);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mDeviceListener.RESPONSE_PARSION_JSON_ERROR);
                            mDeviceListener.onFail(messag);
                        }
                    } else {
                        mDeviceListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mDeviceListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mDeviceListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mDeviceListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param product_id
     * @param user_id
     * @param MAC
     * @param secret_key
     * @param bind_mode             绑定模式(1: owner, 2: share, 3: 自动识别,首个绑定为owner, 其余为share).
     * @param encrypt_method
     * @param headerMap
     * @param mCommonResultListener
     */
    @Override
    public void devicesBind(String product_id, String user_id, String MAC, String secret_key,
                            String bind_mode, String encrypt_method, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("product_id", product_id);
        prarm.put("user_id", user_id);
        prarm.put("MAC", MAC);
        prarm.put("secret_key", secret_key);
        prarm.put("bind_mode", bind_mode);
        prarm.put("encrypt_method", encrypt_method);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_BIND);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param name
     * @param headerMap
     * @param mCommonResultListener
     */
    @Override
    public void devicesGroups(String name, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("name", name);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_GROUPS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param group_id
     * @param device_id
     * @param headerMap
     * @param mCommonResultListener
     */
    @Override
    public void devicesGroupsMembers(String group_id, String device_id, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("group_id", group_id);
        prarm.put("device_id", device_id);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_GROUPS_MEMBERS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param device_id
     * @param msg
     * @param time
     * @param headerMap
     * @param mCommonResultListener
     */
    @Override
    public void devicesIn(String device_id, String msg, String time, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("device_id", device_id);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_IN);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                DeviceInParser deviceInParser = new DeviceInParser();
                try {
                    ErrorMessag messag = deviceInParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = deviceInParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    /**
     *
     * @param device_id
     * @param name
     * @param value
     * @param headerMap
     * @param mCommonResultListener
     */
    @Override
    public void devicesProperties(String device_id, String name, String value, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("device_id", device_id);
        prarm.put("name", name);
        prarm.put("value", value);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_PROPERTIES);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void devicesUnbind(String device_id, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("device_id", device_id);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVICES_UNBIND);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void products(String name, String model, String description, boolean cloud_transcoding,
                         int template_id, HashMap<String, String> headerMap, final ProductListener mProductListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("name", name);
        if (model != null) {
            prarm.put("model", model);
        }
        if (description != null) {
            prarm.put("description", description);
        }
        prarm.put("cloud_transcoding", cloud_transcoding);
        prarm.put("template_id", template_id);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.PRODUCTS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                ProductParser productParser = new ProductParser();
                try {
                    ErrorMessag messag = productParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        Product mProduct = productParser.parserJSON(mJSONObject.toString());
                        if (mProduct != null) {
                            mProductListener.onSuccess(mProduct);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mProductListener.RESPONSE_PARSION_JSON_ERROR);
                            mProductListener.onFail(messag);
                        }
                    } else {
                        mProductListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mProductListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mProductListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mProductListener.onExection(var1);
            }
        });
    }

    @Override
    public void productsDevicesImport(String product_id, String macs, HashMap<String, String> headerMap,
                                      final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("product_id", product_id);
        prarm.put("macs", macs);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.PRODUCTS_DEVICES_IMPORT);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                ProductsDevicesImportParser mProductsDevicesImportParser = new ProductsDevicesImportParser();
                try {
                    ErrorMessag messag = mProductsDevicesImportParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String device_id = mProductsDevicesImportParser.parserJSON(mJSONObject.toString());
                        if (device_id != null) {
                            mCommonResultListener.onSuccess(device_id);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void productsProduct_idDatapoints(String product_id, String name, Integer io, String default_value,
                                             String display_name, String display_widget, String type, String scope,
                                             Integer time_series, String description, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("product_id", product_id);
        prarm.put("name", name);
        if (io == null) {
            prarm.put("io", io.intValue());
        }
        if (default_value == null) {
            prarm.put("default_value", default_value);
        }
        if (display_name == null) {
            prarm.put("display_name", display_name);
        }
        if (display_widget == null) {
            prarm.put("display_widget", display_widget);
        }
        if (type == null) {
            prarm.put("type", type);
        }
        if (scope == null) {
            prarm.put("scope", scope);
        }
        if (time_series == null) {
            prarm.put("time_series", time_series);
        }
        if (description == null) {
            prarm.put("description", description);
        }
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS + "/products/" + product_id);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DATAPOINTS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void developers(String username, String owner_type, String product_id, String action_type,
                           HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("owner_type", owner_type);
        prarm.put("product_id", product_id);
        prarm.put("action_type", action_type);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS + "/products/" + product_id);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVELOPERS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void triggers(String product_id, String name, String property_name, int interval,
                         String compare_type, int threshold, String url, HashMap<String, String> headerMap,
                         final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("product_id", product_id);
        prarm.put("name", name);
        prarm.put("product_id", product_id);
        prarm.put("interval", interval);
        prarm.put("compare_type", compare_type);
        prarm.put("threshold", threshold);
        prarm.put("url", url);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS + "/products/" + product_id);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.TRIGGERS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void apps(WxAppParameter wxAppParameter, HashMap<String, String> headerMap, final WxAppListener mWxAppListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("name", wxAppParameter.getName());
        if (null != wxAppParameter.getDescription()) {
            prarm.put("description", wxAppParameter.getDescription());
        }
        if (null != wxAppParameter.getFeedback()) {
            prarm.put("feedback", wxAppParameter.getFeedback());
        }
        if (null != wxAppParameter.getSource()) {
            prarm.put("source", wxAppParameter.getSource());
        }
        if (null != wxAppParameter.getSms_app_id()) {
            prarm.put("sms_app_id", wxAppParameter.getSms_app_id());
        }
        if (null != wxAppParameter.getSms_tmpl_id()) {
            prarm.put("sms_tmpl_id", wxAppParameter.getSms_tmpl_id());
        }
        prarm.put("sms_account_sid", wxAppParameter.getSms_account_sid());
        prarm.put("sms_auth_token", wxAppParameter.getSms_auth_token());
        if (null != wxAppParameter.getInfo()) {
            prarm.put("info", wxAppParameter.getInfo());
        }

        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.APPS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                WxAppParser wxAppParser = new WxAppParser();
                try {
                    ErrorMessag messag = wxAppParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        WxApp mWxApp = wxAppParser.parserJSON(mJSONObject.toString());
                        if (mWxApp != null) {
                            mWxAppListener.onSuccess(mWxApp);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mWxAppListener.RESPONSE_PARSION_JSON_ERROR);
                            mWxAppListener.onFail(messag);
                        }
                    } else {
                        mWxAppListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mWxAppListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mWxAppListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mWxAppListener.onExection(var1);
            }
        });
    }

    @Override
    public void appsFeedback(String content, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("content", content);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.APPS_FEEDBACK);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void appsDevelopers(String username, String owner_type, String app_id, String action_type,
                               HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("owner_type", owner_type);
        prarm.put("app_id", app_id);
        if (action_type != null) {
            prarm.put("action_type", action_type);
        }
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS + "/apps/" + app_id);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.DEVELOPERS);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void authorization(String verify_code, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("verify_code", verify_code);

        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.AUTHORIZATION);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void authorizationDevicesManage(String username, String owner_type, String device_id, String action_type,
                                           HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        prarm.put("owner_type", owner_type);
        prarm.put("device_id", device_id);
        if (action_type != null) {
            prarm.put("action_type", action_type);
        }

        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.AUTHORIZATION_DEVICES_MANAGE);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void authorizationDevicesToken(String secret_key, String user_id, HashMap<String, String> headerMap, final
    DeviceContrlPortalListener mDeviceContrlPortalListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("secret_key", secret_key);
        prarm.put("user_id", user_id);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.AUTHORIZATION_DEVICES_TOKEN);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                DeviceControlPortalParser deviceControlPortalParser = new DeviceControlPortalParser();
                try {
                    ErrorMessag messag = deviceControlPortalParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        DeviceControlPortal result = deviceControlPortalParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mDeviceContrlPortalListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mDeviceContrlPortalListener.RESPONSE_PARSION_JSON_ERROR);
                            mDeviceContrlPortalListener.onFail(messag);
                        }
                    } else {
                        mDeviceContrlPortalListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mDeviceContrlPortalListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mDeviceContrlPortalListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mDeviceContrlPortalListener.onExection(var1);
            }
        });
    }

    @Override
    public void authorizationUsers(String username, HashMap<String, String> headerMap, final GetCommonResultListener mCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("username", username);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.AUTHORIZATION_USERS + "/" + username);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mCommonResultListener.onFail(messag);
                        }
                    } else {
                        mCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void scheduleCreate(ScheduleCreatParameter scheduleCreatParameter, HashMap<String, String> headerMap, final
    ScheduleCreatListener mScheduleCreatListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        if (null != scheduleCreatParameter.getName()) {
            prarm.put("name", scheduleCreatParameter.getName());
        }
        prarm.put("start_date", scheduleCreatParameter.getStart_date());
        if (null != scheduleCreatParameter.getEnd_date()) {
            prarm.put("end_date", scheduleCreatParameter.getEnd_date());
        }
        if (null != scheduleCreatParameter.getLoop_start_time()) {
            prarm.put("loop_start_time", scheduleCreatParameter.getLoop_start_time());
        }
        if (null != scheduleCreatParameter.getLoop_end_time()) {
            prarm.put("loop_end_time", scheduleCreatParameter.getLoop_end_time());
        }
        prarm.put("loop_interval", scheduleCreatParameter.getLoop_interval());
        prarm.put("work_day", scheduleCreatParameter.getWork_day());
        prarm.put("message_type", scheduleCreatParameter.getMessage_type());
        prarm.put("resource_id", scheduleCreatParameter.getResource_id());
        prarm.put("topic", scheduleCreatParameter.getTopic());
        prarm.put("message", scheduleCreatParameter.getMessage());
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.SCHEDULE_REATE);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                ScheduleCreateParser scheduleCreateParser = new ScheduleCreateParser();
                try {
                    ErrorMessag messag = scheduleCreateParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        ScheduleCreat result = scheduleCreateParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mScheduleCreatListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mScheduleCreatListener.RESPONSE_PARSION_JSON_ERROR);
                            mScheduleCreatListener.onFail(messag);
                        }
                    } else {
                        mScheduleCreatListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mScheduleCreatListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mScheduleCreatListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mScheduleCreatListener.onExection(var1);
            }
        });
    }

    @Override
    public void scheduleDelete(String id, String name, HashMap<String, String> headerMap, final GetCommonResultListener mGetCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("id", id);
        prarm.put("name", name);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.SCHEDULE_DELETE);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mGetCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mGetCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mGetCommonResultListener.onFail(messag);
                        }
                    } else {
                        mGetCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mGetCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mGetCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mGetCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void scheduleLogCreate(String schedule_id, String schedule_time, String sent_time, HashMap<String, String> headerMap, final GetCommonResultListener mGetCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("schedule_id", schedule_id);
        prarm.put("schedule_time", schedule_time);
        prarm.put("sent_time", sent_time);
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.SCHEDULE_LOG_CREATE);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mGetCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mGetCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mGetCommonResultListener.onFail(messag);
                        }
                    } else {
                        mGetCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mGetCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mGetCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mGetCommonResultListener.onExection(var1);
            }
        });
    }

    @Override
    public void scheduleUpdate(ScheduleCreatParameter scheduleCreatParameter, HashMap<String, String> headerMap, final
    GetCommonResultListener mGetCommonResultListener) {
        RequestBean mRequestBean = new RequestBean();
        HashMap<String, Object> prarm = new HashMap<String, Object>();
        prarm.put("id", scheduleCreatParameter.getId());
        if (null != scheduleCreatParameter.getActive()) {
            prarm.put("active", scheduleCreatParameter.getActive());
        }
        if (null != scheduleCreatParameter.getName()) {
            prarm.put("name", scheduleCreatParameter.getName());
        }
        prarm.put("start_date", scheduleCreatParameter.getStart_date());
        if (null != scheduleCreatParameter.getEnd_date()) {
            prarm.put("end_date", scheduleCreatParameter.getEnd_date());
        }
        if (null != scheduleCreatParameter.getLoop_start_time()) {
            prarm.put("loop_start_time", scheduleCreatParameter.getLoop_start_time());
        }
        if (null != scheduleCreatParameter.getLoop_end_time()) {
            prarm.put("loop_end_time", scheduleCreatParameter.getLoop_end_time());
        }
        if (null != scheduleCreatParameter.getLoop_interval()) {
            prarm.put("loop_interval", scheduleCreatParameter.getLoop_interval());
        }
        prarm.put("work_day", scheduleCreatParameter.getWork_day());
        prarm.put("message_type", scheduleCreatParameter.getMessage_type());
        prarm.put("resource_id", scheduleCreatParameter.getResource_id());
        prarm.put("topic", scheduleCreatParameter.getTopic());
        prarm.put("message", scheduleCreatParameter.getMessage());
        mRequestBean.setParamsMap(prarm);
        mRequestBean.setUrl(PORTAL_ADDRESS);
        if (headerMap != null) {
            mRequestBean.setHeadersMap(headerMap);
        }
        mRequestBean.setStrCommand(RequestMand.SCHEDULE_UPDATE);
        mCustomRequest.requestSend(mRequestBean, new ResponseCallback() {
            @Override
            public void onSuccess(JSONObject mJSONObject) {
                SimpleParser simpleParser = new SimpleParser();
                try {
                    ErrorMessag messag = simpleParser.ParseResultPoly(mJSONObject.toString());
                    if (messag == null) {
                        String result = simpleParser.parserJSON(mJSONObject.toString());
                        if (result != null) {
                            mGetCommonResultListener.onSuccess(result);
                        } else {
                            messag = new ErrorMessag();
                            messag.setErrorMsg(mGetCommonResultListener.RESPONSE_PARSION_JSON_ERROR);
                            mGetCommonResultListener.onFail(messag);
                        }
                    } else {
                        mGetCommonResultListener.onFail(messag);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    mGetCommonResultListener.onExection(e);
                }
            }

            @Override
            public void onPrepare(String str) {
                mGetCommonResultListener.onPrepare(str);
            }

            @Override
            public void onFailure(Exception var1) {
                mGetCommonResultListener.onExection(var1);
            }
        });
    }

}
